from dotenv import load_dotenv, find_dotenv
from langchain_openai import ChatOpenAI
from langchain_core.messages import (
    SystemMessage,
    HumanMessage,
    AIMessage,
    trim_messages,
    filter_messages
)

_ = load_dotenv(find_dotenv())

messages = [
    SystemMessage("you're a good assistant, you always respond with a joke."),
    HumanMessage("i wonder why it's called langchain"),
    AIMessage(
        'Well, I guess they thought "WordRope" and "SentenceString" just didn\'t have the same ring to it!'
    ),
    HumanMessage("and who is harrison chasing anyways"),
    AIMessage(
        "Hmmm let me think.\n\nWhy, he's probably chasing after the last cup of coffee in the office!"
    ),
    HumanMessage("what do you call a speechless parrot"),
]

# print(trim_messages(messages, max_tokens=45, strategy="last", token_counter=ChatOpenAI(model="gpt-4o-mini")))

# print(trim_messages(
#     messages, 
#     max_tokens=56, 
#     strategy="last", 
#     token_counter=ChatOpenAI(model="gpt-4o-mini"),
#     allow_partial=True,
#     include_system=True
# ))

print(filter_messages(messages, include_types="human"))